package com.alex.insistence.web.cgform.member.service.impl;

import java.io.Serializable;
import java.util.UUID;

import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alex.insistence.web.cgform.member.entity.MemberEntity;
import com.alex.insistence.web.cgform.member.service.MemberServiceI;
import com.gomore.jeecg.common.Assert;

@Service("memberService")
@Transactional
public class MemberServiceImpl extends CommonServiceImpl implements MemberServiceI {

  public <T> void delete(T entity) {
    super.delete(entity);
    // 执行删除操作配置的sql增强
    this.doDelSql((MemberEntity) entity);
  }

  @Override
  public <T> Serializable save(T entity) {
    return super.save(entity);
  }

  @Override
  public <T> void saveOrUpdate(T entity) {
    super.saveOrUpdate(entity);
  }

  /**
   * 默认按钮-sql增强-新增操作
   * 
   * @param id
   * @return
   */
  public boolean doAddSql(MemberEntity t) {
    return true;
  }

  /**
   * 默认按钮-sql增强-更新操作
   * 
   * @param id
   * @return
   */
  public boolean doUpdateSql(MemberEntity t) {
    return true;
  }

  /**
   * 默认按钮-sql增强-删除操作
   * 
   * @param id
   * @return
   */
  public boolean doDelSql(MemberEntity t) {
    return true;
  }

  /**
   * 替换sql中的变量
   * 
   * @param sql
   * @return
   */
  public String replaceVal(String sql, MemberEntity t) {
    sql = sql.replace("#{id}", String.valueOf(t.getId()));
    sql = sql.replace("#{create_name}", String.valueOf(t.getCreateName()));
    sql = sql.replace("#{create_by}", String.valueOf(t.getCreateBy()));
    sql = sql.replace("#{create_date}", String.valueOf(t.getCreateDate()));
    sql = sql.replace("#{update_name}", String.valueOf(t.getUpdateName()));
    sql = sql.replace("#{update_by}", String.valueOf(t.getUpdateBy()));
    sql = sql.replace("#{update_date}", String.valueOf(t.getUpdateDate()));
    sql = sql.replace("#{sys_org_code}", String.valueOf(t.getSysOrgCode()));
    sql = sql.replace("#{sys_company_code}", String.valueOf(t.getSysCompanyCode()));
    sql = sql.replace("#{idno}", String.valueOf(t.getIdno()));
    sql = sql.replace("#{mobilephone}", String.valueOf(t.getMobilephone()));
    sql = sql.replace("#{name}", String.valueOf(t.getName()));
    sql = sql.replace("#{password}", String.valueOf(t.getPassword()));
    sql = sql.replace("#{wxid}", String.valueOf(t.getWxid()));
    sql = sql.replace("#{alipayid}", String.valueOf(t.getAlipayid()));
    sql = sql.replace("#{grade}", String.valueOf(t.getGrade()));
    sql = sql.replace("#{imgurl}", String.valueOf(t.getImgurl()));
    sql = sql.replace("#{lst_login_time}", String.valueOf(t.getLstLoginTime()));
    sql = sql.replace("#{err_login_time}", String.valueOf(t.getErrLoginTime()));
    sql = sql.replace("#{status}", String.valueOf(t.getStatus()));
    sql = sql.replace("#{UUID}", UUID.randomUUID().toString());
    return sql;
  }

  @Override
  public MemberEntity getByAlipayid(String alipayid) {
    Assert.assertArgumentNotEmpty(alipayid, "alipayid");
    return findUniqueByProperty(MemberEntity.class, "alipayid", alipayid);
  }

  @Override
  public MemberEntity getByWxid(String wxid) {
    Assert.assertArgumentNotEmpty(wxid, "wxid");
    return findUniqueByProperty(MemberEntity.class, "wxid", wxid);
  }

  @Override
  public MemberEntity getByWxaid(String wxaid) {
    Assert.assertArgumentNotEmpty(wxaid, "wxaid");
    return findUniqueByProperty(MemberEntity.class, "wxaid", wxaid);
  }

  @Override
  public MemberEntity getByWxUnionid(String wxUnionid) {
    Assert.assertArgumentNotEmpty(wxUnionid, "wxUnionid");
    return findUniqueByProperty(MemberEntity.class, "wxUnionid", wxUnionid);
  }
  
  
  @Override
  public MemberEntity getByMbrId(String mbrId) {
    Assert.assertArgumentNotEmpty(mbrId, "mbrId");
    return findUniqueByProperty(MemberEntity.class, "memberId", mbrId);
  }
}